package com.hewep.demo.device.mina.core.message;



import com.hewep.demo.device.mina.core.Message;
import org.apache.mina.core.buffer.IoBuffer;


public abstract class AbstractMessage implements Message {
	
	private byte[] data;
		
	private String cmd;
	
	
	
	@Override
	public void setData(byte[] data) {
		this.data = data;
		
	}
	
	public void setData(short[] data) {				
		IoBuffer buffer = IoBuffer.allocate(1024);
		buffer.setAutoExpand(true);
		for(short d : data){
			if(d < 0){
				buffer.putUnsigned(d+256);
			}else{
				buffer.putUnsigned(d);
				
			}
		}		
		
		this.data = buffer.array();
	}

	@Override
	public String getCmd() {
		// TODO Auto-generated method stub
		return this.cmd;
	}

	@Override
	public void setCmd(String cmd) {
		this.cmd = cmd;
		
	}

	@Override
	public byte[] getData() {		
		return this.data;
	}	
}
